// Problem 034: Digit factorials
// 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
// Find the sum of all numbers which are equal to the sum of the factorial of their digits.
// Note: As 1! = 1 and 2! = 2 are not sums they are not included.
// ---------
// 9,999,999	->	2,540,160
// 2,999,999	->	2,177,282
// 2,199,999	->	1,814,403
// 1,899,999	->	1,854,721
// 1,589,999	->	1,491,960
// 1,489,999	->	1,491,864
// 1,497,999	->	1,456,585
// 1,459,999	->	1,451,665
// 1,449,999	->	1,451,569
// 1,458,999	->	1,129,105
// 1,128,999	->	1,128,964
// 1,127,999	->	1,093,684
// 1,093,799	->	1,093,688
// ......

package main

import (
	"fmt"
)

func p034() {
	sum := 0
	for x := 100; x < 1100000; x++ {
		if check034(x) {
			sum += x
		}
	}
	fmt.Println("Problem 034:", sum)
}

func check034(n int) bool {
	FCT := [10]int{1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880}
	sum := n
	for n > 0 {
		sum -= FCT[n%10]
		n /= 10
	}
	return sum == 0
}
